#!/bin/bash
# Date  : 2021-01-15 20:07:09
# Author: scg
# Email : uzz_scg@163.com
# Func  : 批量登陆Linux主机并执行命令
username="root"
password="bit123"
port="22"
timeout=3
#所有集群的Masters安装nfs-kernel-server
cmd0=" systemctl restart rpcbind && systemctl restart nfs-kernel-server && showmount -e"

login(){
    echo ""
    echo "-------------------------------------------------------- "
    echo "username: $username  password: $password  port: $port  timeout=$timeout"
    echo "command: $cmd"
    echo "Remote exec command script"
    echo "--------------------------------------------------------"
    echo ""

    for host in `cat ipMaster.txt`;
    do
        result=""
        result=`sshpass -p "$password" ssh -p $port -o StrictHostKeyChecking=no -o ConnectTimeout=$timeout $username@$host $cmd0 `
        #echo $host >> result.txt
        #echo $result >> result.txt
    done
#所有集群的Nodes节点安装nfs-kernel-server或者nfs-common，为Node负载的nfs-provisioner提供nfs挂载服务
#cmd1="apt update && apt install nfs-kernel-server"
#    for host in `cat ipNodes.txt`;
#    do
#        result=""
#        result=`sshpass -p "$password" ssh -p $port -o StrictHostKeyChecking=no -o ConnectTimeout=$timeout $username@$host $cmd1`
#        echo $host >> result.txt
#        echo $result >> result.txt
#    done
    echo ""
}
login
#ls
